
surface.CreateFont( "PickteamDefault",
{
	font		= "Helvetica",
	size		= 22,
	weight		= 800
})

surface.CreateFont( "PickteamTitle",
{
	font		= "Helvetica",
	size		= 42,
	weight		= 800
})

local TEAM_SELECT =
{
	Init = function( self )
		
		self.HeaderText = self:Add("DLabel")
		self.HeaderText:SetFont( "PickteamTitle" )
		self.HeaderText:SetText( "CHOOSE TEAM" )
		self.HeaderText:SetTextColor( Color( 255, 255, 255, 255 ) )
		self.HeaderText:Dock( TOP )
		self.HeaderText:SetHeight( 42 )
		self.HeaderText:SetContentAlignment( 5 )
		self.HeaderText:SetExpensiveShadow( 2, Color( 0, 0, 0, 200 ) )
		
		self.FooterPanel = self:Add("Panel")
		self.FooterPanel:Dock(BOTTOM)
		self.FooterPanel:SetHeight(26)
		
		self.FooterAuto = self.FooterPanel:Add("DButton")
		self.FooterAuto:Dock(LEFT)
		self.FooterAuto:SetText("Auto-Assign")
		self.FooterAuto.DoClick = function() GAMEMODE:MSAutoAssign() GAMEMODE:HideTeam() end
		
		self.FooterSpec = self.FooterPanel:Add("DButton")
		self.FooterSpec:Dock(LEFT)
		self.FooterSpec:SetText("Spectate")
		self.FooterSpec.DoClick = function() RunConsoleCommand( "changeteam", TEAM_SPECTATOR ) GAMEMODE:HideTeam() end
		
		self.FooterCanc = self.FooterPanel:Add("DButton")
		self.FooterCanc:Dock(RIGHT)
		self.FooterCanc:SetText("Cancel")
		self.FooterCanc.DoClick = function() GAMEMODE:HideTeam() end
		
		self.MainPanel = self:Add("Panel")
		self.MainPanel:Dock(FILL)
		
		--Admin button
		self.AdminPanel = self.MainPanel:Add("Panel")
		self.AdminPanel:Dock(LEFT)
		self.AdminPanel:SetWidth( 340 )
		
		self.AdminLabel = self.AdminPanel:Add("DLabel")
		self.AdminLabel:SetFont( "PickteamDefault" )
		self.AdminLabel:SetText( "ADMINISTRATORS" )
		self.AdminLabel:SetTextColor( Color( 255, 255, 255, 255 ) )
		self.AdminLabel:Dock( TOP )
		self.AdminLabel:SetHeight( 22 )
		self.AdminLabel:SetContentAlignment( 5 )
		
		self.AdminPcnt = self.AdminPanel:Add("DLabel")
		self.AdminPcnt:SetFont( "PickteamDefault" )
		self.AdminPcnt:SetTextColor( Color( 255, 255, 255, 255 ) )
		self.AdminPcnt:Dock( TOP )
		self.AdminPcnt:SetHeight( 22 )
		self.AdminPcnt:SetContentAlignment( 5 )
		
		self.AdminBtn = self.AdminPanel:Add("DImageButton")
		self.AdminBtn:Dock(TOP)
		self.AdminBtn:SetImage( "vgui/teamlogo_admin.vtf" )
		self.AdminBtn:SetHeight(340)
		self.AdminBtn.DoClick = function() RunConsoleCommand( "changeteam", TEAM_ADMIN ) GAMEMODE:HideTeam() end
		
		--Minge button
		self.MingePanel = self.MainPanel:Add("Panel")
		self.MingePanel:Dock(RIGHT)
		self.MingePanel:SetWidth( 340 )
		
		self.MingeLabel = self.MingePanel:Add("DLabel")
		self.MingeLabel:SetFont( "PickteamDefault" )
		self.MingeLabel:SetText( "MINGEBAGS" )
		self.MingeLabel:SetTextColor( Color( 255, 255, 255, 255 ) )
		self.MingeLabel:Dock( TOP )
		self.MingeLabel:SetHeight( 22 )
		self.MingeLabel:SetContentAlignment( 5 )
		
		self.MingePcnt = self.MingePanel:Add("DLabel")
		self.MingePcnt:SetFont( "PickteamDefault" )
		self.MingePcnt:SetTextColor( Color( 255, 255, 255, 255 ) )
		self.MingePcnt:Dock( TOP )
		self.MingePcnt:SetHeight( 22 )
		self.MingePcnt:SetContentAlignment( 5 )
		
		self.MingeBtn = self.MingePanel:Add("DImageButton")
		self.MingeBtn:Dock(TOP)
		self.MingeBtn:SetImage( "vgui/teamlogo_mingebag.vtf" )
		self.MingeBtn:SetHeight(340)
		self.MingeBtn.DoClick = function() RunConsoleCommand( "changeteam", TEAM_MBAGS ) GAMEMODE:HideTeam() end
		
	end,
	
	PerformLayout = function( self )

		self:SetSize( 700, ScrH() - 350 )
		self:SetPos( ScrW() / 2 - 350, 175 )

	end,
	
	Think = function( self, w, h )
		local acnt = #team.GetPlayers(TEAM_ADMIN)
		local mcnt = #team.GetPlayers(TEAM_MBAGS)
		self.AdminPcnt:SetText("x"..acnt)
		self.MingePcnt:SetText("x"..mcnt)
		self.AdminBtn:SetDisabled(acnt>mcnt or LocalPlayer():Team()==TEAM_ADMIN)
		self.MingeBtn:SetDisabled(acnt<mcnt or LocalPlayer():Team()==TEAM_MBAGS)
		self.FooterCanc:SetDisabled(LocalPlayer():Team()==TEAM_UNASSIGNED) 
	end,
	
	Paint = function( self, w, h )

		draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 20, 50, 200 ) )
		
	end,
}

TEAM_SELECT = vgui.RegisterTable( TEAM_SELECT, "EditablePanel" );

function GM:ShowTeam()

	if ( !IsValid( g_Teamselect ) ) then
		g_Teamselect = vgui.CreateFromTable( TEAM_SELECT )
	end

	if ( IsValid( g_Teamselect ) ) then
		g_Teamselect:Show()
		g_Teamselect:MakePopup()
		g_Teamselect:SetKeyboardInputEnabled( false )
	end

end

function GM:HideTeam()

	if ( IsValid( g_Teamselect ) ) then
		g_Teamselect:Hide()
	end

end